
var numDecodings = function(s: string): number {
    if(s==null || s.length ==0 || s[0]=='0')
        return 0;
    if(s.length==1)
        return 1;
 
    const dp = new Array(s.length).fill(0);    
    dp[0]=1;
    if(Number.parseInt(s.substring(0,2))>26){
        if(s.charAt(1)!='0'){
            dp[1]=1;
        }else{
            dp[1]=0;
        }
    }else{
        if(s.charAt(1)!='0'){
            dp[1]=2;
        }else{
            dp[1]=1;
        }
    }
 
    for(var i=2; i<s.length; i++){
        if(s.charAt(i)!='0'){
            dp[i]+=dp[i-1];
        }
 
        var val = Number.parseInt(s.substring(i-1, i+1));
        if(val<=26 && val >=10){
            dp[i]+=dp[i-2];
        }
    }
 
    return dp[s.length-1];
};

var answer91 = numDecodings("12")
console.assert(answer91 === 2)
console.assert(numDecodings("") == 0);
console.assert(numDecodings("10") == 1);
console.assert(numDecodings("27") == 1);
console.assert(numDecodings("00") == 0);
console.assert(numDecodings("01") == 0);
console.assert(numDecodings("17") == 2);

console.log('The End')